var e = require;
var t = module;
var o = exports;
var ii, nn = this && this.__extends || (ii = function (t, e) {
    return (ii = Object.setPrototypeOf || {
        __proto__: []
    }
        instanceof Array &&
        function (t, e) {
            t.__proto__ = e
        } ||
        function (t, e) {
            for (var o in e) Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o])
        })(t, e)
},
    function (t, e) {
        function o() {
            this.constructor = t
        }
        ii(t, e),
            t.prototype = null === e ? Object.create(e) : (o.prototype = e.prototype, new o)
    }
),
    rr = this && this.__awaiter ||
        function (t, e, o, i) {
            return new (o || (o = Promise))(function (n, a) {
                function r(t) {
                    try {
                        l(i.next(t))
                    } catch (e) {
                        a(e)
                    }
                }
                function s(t) {
                    try {
                        l(i.
                            throw(t))
                    } catch (e) {
                        a(e)
                    }
                }
                function l(t) {
                    var e;
                    t.done ? n(t.value) : (e = t.value, e instanceof o ? e : new o(function (t) {
                        t(e)
                    })).then(r, s)
                }
                l((i = i.apply(t, e || [])).next())
            })
        };
var oo = (this && this.__decorate) ||
    function (e, t, a, n) {
        var i,
            o = arguments.length,
            s = o < 3 ? t : null === n ? (n = Object.getOwnPropertyDescriptor(t, a)) : n;
        if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) s = Reflect.decorate(e, t, a, n);
        else
            for (var r = e.length - 1; r >= 0; r--)
                (i = e[r]) && (s = (o < 3 ? i(s) : o > 3 ? i(t, a, s) : i(t, a)) || s);
        return o > 3 && s && Object.defineProperty(t, a, s), s;
    };
Object.defineProperty(o, "__esModule", { value: !0 });
var a = e("BaseModuleUI"),
    n = e("NotifyEventType"),
    i = e("GlobalParams"),
    r = e("AssetsManager"),
    s = e("AudioManager"),
    l = e("CommonHelper"),
    _ = e("EquipInfo"),
    c = e("Game"),
    d = e("RoleSoldierInfo"),
    h = e("sdkConfig"),
    u = e("AD"),
    p = e("Toast"),
    m = e("BuyEquipInfo"),
    f = cc._decorator,
    v = f.ccclass,
    g = f.property,
    y = (function (e) {
        function t() {
            var t = (null !== e && e.apply(this, arguments)) || this;
            return (
                (t.skill_one_btn = null),
                (t.skill_two_btn = null),
                (t.skill_three_btn = null),
                (t.one_add_skill_node = null),
                (t.two_add_skill_node = null),
                (t.three_add_skill_node = null),
                (t.skill_one_cooling_label = null),
                (t.skill_two_cooling_label = null),
                (t.skill_three_cooling_label = null),
                (t.team_kill_left = null),
                (t.team_kill_right = null),
                (t.kill_num_label = null),
                (t.die_num_label = null),
                (t.assist_num_label = null),
                (t.player_skill_one_image = null),
                (t.player_skill_two_image = null),
                (t.player_skill_one_name = null),
                (t.player_skill_two_name = null),
                (t.top_node_item = null),
                (t.coin_num_label = null),
                (t.equip_item = null),
                (t.buy_equip_item = null),
                (t.myNomEquipInfo = []),
                (t.show_equip_info = null),
                t
            );
        }
        return (
            nn(t, e),
            (t.prototype.initView = function () {
                e.prototype.initView.call(this),
                    this.buy_equip_item.setPosition(cc.v2(-520, 110)),
                    (this.buy_equip_item.active = !1),
                    (i.GlobalParams.GameTeamKillInfo = [0, 0]),
                    (this.team_kill_left.string = "" + i.GlobalParams.GameTeamKillInfo[0]),
                    (this.team_kill_right.string = "" + i.GlobalParams.GameTeamKillInfo[1]),
                    this.showMyKillInfo(),
                    this.showAddSkillNode(),
                    this.showHeroSkillInfo(),
                    this.updatePlayerCoin();
                var t = i.GlobalParams.MatchGamePlayer[i.GlobalParams.MatchMyIndex].player_skill;
                (this.player_skill_one_image.spriteFrame = r.default
                    .getInstance()
                    .getPlayerSkillFrame("skill_" + (h.default.platform == h.EPlatform.TikTok ? "dy_" : "") + t[0])),
                    (this.player_skill_one_name.string = d.default.Player_Skill_Info[t[0] - 1].name),
                    (this.player_skill_two_image.spriteFrame = r.default
                        .getInstance()
                        .getPlayerSkillFrame(
                            "skill_" + (h.default.platform == h.EPlatform.TikTok ? "dy_" : "") + t[1]
                        )),
                    (this.player_skill_two_name.string = d.default.Player_Skill_Info[t[1] - 1].name),
                    (this.myNomEquipInfo =
                        _.default.equip_nominate_info[
                            i.GlobalParams.MatchGamePlayer[i.GlobalParams.MatchMyIndex].role_id
                        ].nom_equip);
            }),
            (t.prototype.addEvent = function () {
                this.attachEvent(n.default.SEND_PLAYER_SKILL_COOLING_TIME, this.showCoolingTime, this),
                    this.attachEvent(n.default.SEND_PLAYER_LEVEL_UP_INFO, this.playerLevelUp, this),
                    this.attachEvent(n.default.SEND_ROLE_BE_KILL_INFO, this.showTeamKillInfo, this),
                    this.attachEvent(n.default.SEND_UPDATE_MATCH_PLAYER_INFO, this.updatePlayerCoin, this),
                    this.attachEvent(n.default.SEND_UPDATE_PLAYER_REVIVE_INFO, this.showHeroSkillInfo, this),
                    this.attachEvent(n.default.SEND_ADD_SKILL_LEVEL_INDEX, this.clickAddSkill, this),
                    this.attachEvent(n.default.SEND_USE_PLAYER_SKILL_INDEX, this.usePlayerSkill, this),
                    this.attachEvent(n.default.SEND_PLAYER_USE_PLAYER_SKILL_OVER, this.playerUseskillOver, this);
            }),
            (t.prototype.OnClick = function (t) {
                e.prototype.OnClick.call(this, t);
                var o = t.node.name;
                switch (o) {
                    case "add_skill_1":
                    case "add_skill_2":
                    case "add_skill_3":
                        var a = l.default.getNameType(o, "add_skill_");
                        this.clickAddSkill("", a - 1);
                        break;
                    case "player_skill_one":
                    case "player_skill_two":
                        this.usePlayerSkill("", "player_skill_one" == o ? 1 : 2);
                        break;
                    case "menu_btn":
                    case "kill_info_node":
                        h.default.platform == h.EPlatform.TikTok && u.default.getInstance().PauseRecorder(),
                            cc
                                .find("Canvas")
                                .addChild(cc.instantiate(r.default.getInstance().getFightPrefab("GameMenuViewUI")));
                        break;
                    case "go_fight_btn":
                        this.showTopInfoNode(0);
                        break;
                    case "gather_btn":
                        this.showTopInfoNode(1);
                        break;
                    case "retreat_btn":
                        this.showTopInfoNode(2);
                        break;
                    case "praise_btn":
                        this.showTopInfoNode(3);
                        break;
                    case "setting_btn":
                        h.default.platform == h.EPlatform.TikTok && u.default.getInstance().PauseRecorder(),
                            this.uiManager.showPopup("SettingViewUI");
                        break;
                    case "coin_node":
                        h.default.platform == h.EPlatform.TikTok && u.default.getInstance().PauseRecorder(),
                            cc
                                .find("Canvas")
                                .addChild(cc.instantiate(r.default.getInstance().getFightPrefab("GameEquipViewUI")));
                        break;
                    case "equip_item":
                        this.quickBuyEquip();
                }
            }),
            (t.prototype.showTopInfoNode = function (e) {
                var t = this;
                0 == e
                    ? s.default.getInstance().playFx("go_fight")
                    : 1 == e
                        ? s.default.getInstance().playFx("gather")
                        : 2 == e
                            ? s.default.getInstance().playFx("retreat")
                            : 3 == e && s.default.getInstance().playFx("good_job"),
                    this.unscheduleAllCallbacks();
                for (var o = 0; o < 4; o++) this.top_node_item.children[0].children[o].active = o == e;
                (this.top_node_item.children[1].getChildByName("head").getComponent(cc.Sprite).spriteFrame = r.default
                    .getInstance()
                    .getGameHoreHeadFrame(
                        "hero_" +
                        d.default.Role_info[i.GlobalParams.MatchGamePlayer[i.GlobalParams.MatchMyIndex].role_id].id
                    )),
                    (this.top_node_item.children[1].children[0].active = i.GlobalParams.MatchMyIndex % 2 == 0),
                    (this.top_node_item.children[1].children[0].active = i.GlobalParams.MatchMyIndex % 2 != 0),
                    (this.top_node_item.active = !0),
                    this.scheduleOnce(function () {
                        t.top_node_item.active = !1;
                    }, 1);
            }),
            (t.prototype.usePlayerSkill = function (e, t) {
                var o = 1 == t ? this.player_skill_one_image.node.parent : this.player_skill_two_image.node.parent,
                    a = o.name;
                if (!o.getChildByName("cooling").active) {
                    var r =
                        i.GlobalParams.MatchGamePlayer[i.GlobalParams.MatchMyIndex].player_skill[
                        "player_skill_one" == a ? 0 : 1
                        ];
                    this.emitEvent(n.default.SEND_PLAYER_USE_PLAYER_SKILL, r);
                }
            }),
            (t.prototype.playerUseskillOver = function (e, t) {
                var o = t;
                if (o.cool) {
                    var a = (
                        0 == i.GlobalParams.MatchGamePlayer[i.GlobalParams.MatchMyIndex].player_skill.indexOf(o.id)
                            ? this.player_skill_one_image.node.parent
                            : this.player_skill_two_image.node.parent
                    ).getChildByName("cooling");
                    a.active = !0;
                    var n = d.default.Player_Skill_Info[o.id - 1].cooling;
                    i.GlobalParams.ChangeGameMode == c.GameType.endless_mode && (n /= 2),
                        this.playerSkillCooling(a, n, n);
                } else p.default.showNewToast("附近暂无目标");
            }),
            (t.prototype.showCoolingTime = function (e, t) {
                var o = Number(t.time.toFixed(1));
                1 == t.type
                    ? ((this.skill_one_cooling_label.node.parent.active = !0),
                        (this.skill_one_btn.getChildByName("use_skill").active = !1),
                        this.btnCoolingInfo(this.skill_one_cooling_label, o, o))
                    : 2 == t.type
                        ? ((this.skill_two_cooling_label.node.parent.active = !0),
                            (this.skill_two_btn.getChildByName("use_skill").active = !1),
                            this.btnCoolingInfo(this.skill_two_cooling_label, o, o))
                        : 3 == t.type &&
                        ((this.skill_three_cooling_label.node.parent.active = !0),
                            (this.skill_three_btn.getChildByName("use_skill").active = !1),
                            this.btnCoolingInfo(this.skill_three_cooling_label, o, o));
            }),
            (t.prototype.btnCoolingInfo = function (e, t, o) {
                var a = this,
                    n = e.node.parent.getChildByName("bg").getComponent(cc.Sprite);
                t <= 0
                    ? ((n.fillRange = 1), (e.node.parent.active = !1))
                    : ((t = Number(t.toFixed(1))),
                        (e.string = "" + t),
                        cc
                            .tween(n)
                            .to(1, { fillRange: t / o })
                            .call(function () {
                                t--, a.btnCoolingInfo(e, t, o);
                            })
                            .start());
            }),
            (t.prototype.clickAddSkill = function (e, t) {
                if (
                    (0 == t && this.one_add_skill_node.active) ||
                    (1 == t && this.two_add_skill_node) ||
                    (2 == t && this.three_add_skill_node)
                ) {
                    i.GlobalParams.MatchGamePlayer[i.GlobalParams.MatchMyIndex].skill_info[t]++;
                    var o = i.GlobalParams.MatchGamePlayer[i.GlobalParams.MatchMyIndex];
                    0 == t
                        ? (i.GlobalParams.GamePlayerInfo[i.GlobalParams.MatchMyIndex].skill_1 +=
                            d.default.Role_info[o.role_id].S1_attack_up)
                        : 1 == t
                            ? (i.GlobalParams.GamePlayerInfo[i.GlobalParams.MatchMyIndex].skill_2 +=
                                d.default.Role_info[o.role_id].S2_attack_up)
                            : 2 == t &&
                            (i.GlobalParams.GamePlayerInfo[i.GlobalParams.MatchMyIndex].skill_3 +=
                                d.default.Role_info[o.role_id].S3_attack_up),
                        this.showAddSkillNode();
                }
            }),
            (t.prototype.playerLevelUp = function (e, t) {
                t == i.GlobalParams.MatchMyIndex && this.showAddSkillNode();
            }),
            (t.prototype.showAddSkillNode = function () {
                var e = i.GlobalParams.MatchGamePlayer[i.GlobalParams.MatchMyIndex],
                    t = e.skill_info[0] + e.skill_info[1] + e.skill_info[2];
                (this.one_add_skill_node.active = e.level > t && e.skill_info[0] < 5),
                    (this.two_add_skill_node.active = e.level > t && e.skill_info[1] < 5),
                    (this.three_add_skill_node.active = e.level > t && e.skill_info[2] < 5),
                    (this.skill_one_btn.getChildByName("not_learn_bg").active = 0 == e.skill_info[0]),
                    (this.skill_two_btn.getChildByName("not_learn_bg").active = 0 == e.skill_info[1]),
                    (this.skill_three_btn.getChildByName("not_learn_bg").active = 0 == e.skill_info[2]),
                    (this.skill_one_btn.getComponent(cc.Button).interactable = 0 != e.skill_info[0]),
                    (this.skill_two_btn.getComponent(cc.Button).interactable = 0 != e.skill_info[1]),
                    (this.skill_three_btn.getComponent(cc.Button).interactable = 0 != e.skill_info[2]),
                    (this.skill_one_btn.getChildByName("level_bg").getComponent(cc.Sprite).fillRange =
                        -0.2 * e.skill_info[0]),
                    (this.skill_two_btn.getChildByName("level_bg").getComponent(cc.Sprite).fillRange =
                        -0.2 * e.skill_info[1]),
                    (this.skill_three_btn.getChildByName("level_bg").getComponent(cc.Sprite).fillRange =
                        -0.2 * e.skill_info[2]);
            }),
            (t.prototype.showTeamKillInfo = function (e, t) {
                var o = t;
                o.kill < 11 &&
                    o.be_kill < 11 &&
                    (o.kill % 2 == 0 ? i.GlobalParams.GameTeamKillInfo[0]++ : i.GlobalParams.GameTeamKillInfo[1]++,
                        (this.team_kill_left.string = "" + i.GlobalParams.GameTeamKillInfo[0]),
                        (this.team_kill_right.string = "" + i.GlobalParams.GameTeamKillInfo[1]),
                        this.showMyKillInfo());
            }),
            (t.prototype.showMyKillInfo = function () {
                var e = i.GlobalParams.MatchGamePlayer[i.GlobalParams.MatchMyIndex];
                (this.kill_num_label.string = "" + e.kill_info[0]),
                    (this.die_num_label.string = "" + e.kill_info[1]),
                    (this.assist_num_label.string = "" + e.kill_info[2]);
            }),
            (t.prototype.playerSkillCooling = function (e, t, o) {
                var a = this;
                if (t <= 0) e.active = !1;
                else {
                    e.getChildByName("cooling_num").getComponent(cc.Label).string = "" + t;
                    var n = e.getChildByName("bg").getComponent(cc.Sprite);
                    cc.tween(n)
                        .to(1, { fillRange: t / o })
                        .call(function () {
                            t--, a.playerSkillCooling(e, t, o);
                        })
                        .start();
                }
            }),
            (t.prototype.showHeroSkillInfo = function () {
                var e = i.GlobalParams.MatchGamePlayer[i.GlobalParams.MatchMyIndex];
                (this.skill_one_btn.getChildByName("skill_icon").getComponent(cc.Sprite).spriteFrame = r.default
                    .getInstance()
                    .getHeroSkilIcon(d.default.Role_info[e.role_id].id + "a")),
                    (this.skill_two_btn.getChildByName("skill_icon").getComponent(cc.Sprite).spriteFrame = r.default
                        .getInstance()
                        .getHeroSkilIcon(d.default.Role_info[e.role_id].id + "b")),
                    (this.skill_three_btn.getChildByName("skill_icon").getComponent(cc.Sprite).spriteFrame = r.default
                        .getInstance()
                        .getHeroSkilIcon(d.default.Role_info[e.role_id].id + "c")),
                    (this.skill_one_btn.getChildByName("skill_des").getComponent(cc.Label).string =
                        d.default.Role_info[e.role_id].S1_des),
                    (this.skill_two_btn.getChildByName("skill_des").getComponent(cc.Label).string =
                        d.default.Role_info[e.role_id].S2_des),
                    (this.skill_three_btn.getChildByName("skill_des").getComponent(cc.Label).string =
                        d.default.Role_info[e.role_id].S3_des);
            }),
            (t.prototype.quickBuyEquip = function () {
                var e = this;
                if (this.equip_item.active) {
                    s.default.getInstance().playFx("buy_equip");
                    for (
                        var t = this.show_equip_info.eq_sale,
                        o = i.GlobalParams.MatchGamePlayer[i.GlobalParams.MatchMyIndex].equip_info,
                        a = [],
                        r = 0,
                        l = 0;
                        l < this.show_equip_info.eq_need.length;
                        l++
                    )
                        -1 != o.indexOf(this.show_equip_info.eq_need[l]) &&
                            ((t -= _.default.eqquip_info[this.show_equip_info.eq_need[l]].eq_sale),
                                a.push(o.indexOf(this.show_equip_info.eq_need[l])));
                    for (l = 0; l < o.length; l++) o[l] > 0 && r++;
                    if (t == this.show_equip_info.eq_sale && r > 5) cc.log("=====已达到购买上限=====");
                    else {
                        for (l = 0; l < a.length; l++) o[a[l]] = 0;
                        for (
                            o[o.indexOf(0)] = this.show_equip_info.eq_ID,
                            i.GlobalParams.MatchGamePlayer[i.GlobalParams.MatchMyIndex].coin -= t,
                            i.GlobalParams.MatchGamePlayer[i.GlobalParams.MatchMyIndex].equip_info = o,
                            m.default.playerBuyEquipInfo(i.GlobalParams.MatchMyIndex, function () {
                                e.emitEvent(
                                    n.default.SEND_UPDATE_BUY_EQUIP_NEW_ADD_INFO,
                                    i.GlobalParams.MatchMyIndex
                                );
                            }),
                            l = 0;
                            l < this.show_equip_info.eq_need.length;
                            l++
                        ) {
                            var c = i.GlobalParams.MyNomEquipInfo.indexOf(this.show_equip_info.eq_need[l]);
                            -1 != c && i.GlobalParams.MyNomEquipInfo.splice(c, 1);
                        }
                        i.GlobalParams.MyNomEquipInfo.splice(
                            i.GlobalParams.MyNomEquipInfo.indexOf(this.show_equip_info.eq_ID),
                            1
                        ),
                            this.emitEvent(n.default.SEND_UPDATE_MATCH_PLAYER_INFO),
                            (this.buy_equip_item.active = !0),
                            this.buy_equip_item.stopAllActions(),
                            this.buy_equip_item.getComponent(cc.ParticleSystem).resetSystem(),
                            cc
                                .tween(this.buy_equip_item)
                                .to(1, { position: cc.v2(0, -100) })
                                .call(function () {
                                    (e.buy_equip_item.active = !1), e.buy_equip_item.setPosition(cc.v2(-520, 110));
                                })
                                .start();
                    }
                }
            }),
            (t.prototype.updatePlayerCoin = function () {
                var e = i.GlobalParams.MatchGamePlayer[i.GlobalParams.MatchMyIndex].coin;
                if (((this.coin_num_label.string = "" + e), 0 != i.GlobalParams.MyNomEquipInfo.length)) {
                    var t = i.GlobalParams.MyNomEquipInfo[0],
                        o = _.default.eqquip_info[t],
                        a = i.GlobalParams.MatchGamePlayer[i.GlobalParams.MatchMyIndex].equip_info,
                        n = 0;
                    if (o.eq_level > 1)
                        for (var s = 0; s < o.eq_need.length; s++)
                            -1 != a.indexOf(o.eq_need[s]) && (n += _.default.eqquip_info[o.eq_need[s]].eq_sale);
                    e >= o.eq_sale - n
                        ? (-1 == this.myNomEquipInfo.indexOf(t) &&
                            (t = i.GlobalParams.MyNomEquipInfo[1]) &&
                            e >= _.default.eqquip_info[t].eq_sale - n &&
                            (o =
                                -1 == this.myNomEquipInfo.indexOf(t)
                                    ? (t = i.GlobalParams.MyNomEquipInfo[2]) &&
                                        e >= _.default.eqquip_info[t].eq_sale - n
                                        ? _.default.eqquip_info[t]
                                        : _.default.eqquip_info[i.GlobalParams.MyNomEquipInfo[1]]
                                    : _.default.eqquip_info[t]),
                            (this.show_equip_info = o),
                            (this.equip_item.children[0].getComponent(cc.Sprite).spriteFrame = r.default
                                .getInstance()
                                .getEquipIconFrame("equip_" + o.eq_ID)),
                            (this.equip_item.children[3].getComponent(cc.Label).string = "" + o.eq_name),
                            (this.equip_item.children[4].getComponent(cc.Label).string = "" + (o.eq_sale - n)),
                            (this.equip_item.active = !0))
                        : (this.equip_item.active = !1);
                } else this.equip_item.active = !1;
            }),
            oo([g(cc.Node)], t.prototype, "skill_one_btn", void 0),
            oo([g(cc.Node)], t.prototype, "skill_two_btn", void 0),
            oo([g(cc.Node)], t.prototype, "skill_three_btn", void 0),
            oo([g(cc.Node)], t.prototype, "one_add_skill_node", void 0),
            oo([g(cc.Node)], t.prototype, "two_add_skill_node", void 0),
            oo([g(cc.Node)], t.prototype, "three_add_skill_node", void 0),
            oo([g(cc.Label)], t.prototype, "skill_one_cooling_label", void 0),
            oo([g(cc.Label)], t.prototype, "skill_two_cooling_label", void 0),
            oo([g(cc.Label)], t.prototype, "skill_three_cooling_label", void 0),
            oo([g(cc.Label)], t.prototype, "team_kill_left", void 0),
            oo([g(cc.Label)], t.prototype, "team_kill_right", void 0),
            oo([g(cc.Label)], t.prototype, "kill_num_label", void 0),
            oo([g(cc.Label)], t.prototype, "die_num_label", void 0),
            oo([g(cc.Label)], t.prototype, "assist_num_label", void 0),
            oo([g(cc.Sprite)], t.prototype, "player_skill_one_image", void 0),
            oo([g(cc.Sprite)], t.prototype, "player_skill_two_image", void 0),
            oo([g(cc.Label)], t.prototype, "player_skill_one_name", void 0),
            oo([g(cc.Label)], t.prototype, "player_skill_two_name", void 0),
            oo([g(cc.Node)], t.prototype, "top_node_item", void 0),
            oo([g(cc.Label)], t.prototype, "coin_num_label", void 0),
            oo([g(cc.Node)], t.prototype, "equip_item", void 0),
            oo([g(cc.Node)], t.prototype, "buy_equip_item", void 0),
            oo([v], t)
        );
    })(a.default);
o.default = y;
